package com.wwl.cms.basic.utils;

import org.apache.shardingsphere.core.strategy.keygen.SnowflakeShardingKeyGenerator;

/**
 * @author wwl
 * @version 1.0
 * @date 2021/10/30 16:46
 * @description:
 */
public class SnowFlakeUtils {
    public static Comparable<?>  getId(Long workerId) {
        if (!(workerId >= 0 && workerId < 1024L)) {
            throw new RuntimeException(String.format("workerId is not support range must be [0,1024)"));
        }
        SnowflakeShardingKeyGenerator snowflakeShardingKeyGenerator = new SnowflakeShardingKeyGenerator();
        snowflakeShardingKeyGenerator.getProperties().put("worker.id", String.valueOf(workerId));
        Comparable<?> generateKey = snowflakeShardingKeyGenerator.generateKey();
        return generateKey;
    }
}
